/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package function;

import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import mainpackage.Constant;
import mainpackage.GameBean;
import mainpackage.InputInterFace;
import mainpackage.MainCanvas;
import mainpackage.MainGame;
import mainpackage.MainLogic;
import mainpackage.MainView;
import mainpackage.ResManager;
import mainpackage.Tools;
import ui.UiEquipment;

/**
 *
 * @author Administrator
 */
public class Friend {

    private Image[] imgArray = null;
    public String[] sArray = null;
    public int[] iArray = null;
    private int startX = 0;
    public int startY = 0;
    private int w = 0;
    public int h = 0;
    private int selectColor = 0x00CCFF;
    private int blackColor = 0x000000;
    private int whiteColor = 0xFFFFFF;
    public int iPositionY = 0;
    private int iHeight = 0;
    private byte num = 0;//每页最多显示的好友数量
    private boolean bUiKeyPressLock = false;
    public byte bySelectIndex; //一级选中状态，从1开始
    public byte bySubSelectIndex; //子选择索引，从1开始
    public byte selectNum;
    private short sCurrentPage, sTotalPage;
    public byte byState;
    private int menuWidth = 0;//菜单宽度
    private int menuHeight = 0;//菜单高度
    private int menuH;//每条menu菜单的高度
    private int menuSpaceH;//每2个menu间的间隔高度
    private byte menuSelectIndex;//菜单选择索引，从1开始
    public int menuPositionY = 0;
    private String[] menuName;//菜单项
    public byte byPopUpState = -1; //记录界面弹出层的UI状态变化
    private int friendNum;//好友数量
    private String[] duty;//好友职业
    private int[] level;//好友级别
    private String[] name;//好友名字
    private long[] id;//好友id
    private byte[] online;//是否在线，1为在线
    private int tempIndex;//临时索引

    /******************************好友列表***********************************/
    public void initFriendList() {
        bUiKeyPressLock = false;
        bySelectIndex = 1;
        //测试
//        init(30);
//        for (int i = 0; i < 30; i++) {
//            init(i, 123, "测试" + i, i, "Paladin1", (byte) 1);
//        }
//        GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
//        GameBean.BY_CMD_FRIEND_TYPE = 1;

        switch (GameBean.BY_CMD_FRIEND_TYPE) {
            case 1://好友
                bySubSelectIndex = 1;
                break;
            case 2://黑名单
                bySubSelectIndex = 2;
                break;
            case 4://最近联系
                bySubSelectIndex = 3;
                break;
        }
        byState = 0;
        sArray = new String[]{"我的好友", "添加", "--------------", "/", "页",// 0 - 4
            "好友", "黑名单", "最近联系", "最近联系", "武师", "刺客", "术士", // 5 - 11
            "【", "】", " - ", "：", "发送消息", "", "【武师】25 - 测试名字长度",// 12 - 18
            "1 好友", "2 黑名单", "3 最近联系", "确定", "返回"// 19 - 23
        };
        //#if NOKIA_E72
//#         num = 5;
        //#else
        num = 10;
        //#endif

        sCurrentPage = 1;
        selectNum = (byte) ((sCurrentPage * this.num < friendNum) ? this.num + 2
                : (byte) (friendNum - (sCurrentPage - 1) * this.num + 2));
        sTotalPage = (short) ((friendNum % this.num > 0 || friendNum == 0)
                ? (friendNum / this.num + 1) : (friendNum / this.num));
        switch (bySubSelectIndex) {
            case 1://好友
                sArray[0] = "我的好友";
                break;
            case 2://黑名单
                sArray[0] = "黑名单";
                break;
            case 3://最近联系
                sArray[0] = "最近联系人";
                break;
        }
        //#if NOKIA_S60V5
         imgArray = new Image[10];
         imgArray[0] = ResManager.createImage(90000017);//背景图片
         imgArray[1] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 100, 0x252525);//半透明背景图片
         imgArray[2] = ResManager.createImage(90000041);//箭头图片
         imgArray[3] = Tools.makeBlueMask();//蓝光图片
         imgArray[4] = ResManager.createImage(90000043);//确定、返回图片
         //弹出层图片
         imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);//菜单背景图片
         imgArray[6] = ResManager.createImage(90000047);//数字图片
         imgArray[7] = ResManager.createImage(90000084);//方向键
         imgArray[8] = ResManager.createImage(90000085);//确定键
         imgArray[9] = ResManager.createImage(90000086);//底部蓝条
         iPositionY = Constant.UI_START_Y + 41;
        //#else
//#        imgArray = new Image[7];
//#        try {
            //#if NOKIA_S40V3 || MOTO || K790
            //#elif NORMAL_240_400
//# //            imgArray[0] = ResManager.createImage(90000017);
//# //            imgArray[0] = Tools.ZoomImage(imgArray[0], Constant.DRAW_WIDTH, Constant.DRAW_HEIGHT);
            //#else
//#            imgArray[0] = ResManager.createImage(90000017);//背景图片
            //#endif
//#
//#            imgArray[1] = Tools.makeTransparent(Constant.SCREEN_WIDTH, 10, 100, 0x252525);//半透明背景图片
//#            imgArray[2] = ResManager.createImage(90000041);//箭头图片
//#            imgArray[3] = Tools.makeBlueMask();//蓝光图片
//#            imgArray[4] = ResManager.createImage(90000043);//确定、返回图片
//#            //弹出层图片
//#            imgArray[5] = Tools.makeTransparent(ResManager.createImage(90000051), -1);//菜单背景图片
//#            imgArray[6] = ResManager.createImage(90000047);//数字图片
//#        } catch (Exception e) {
//#            e.printStackTrace();
//#        }
//#        iPositionY = Constant.UI_START_Y + 21;
        //#endif
    }

    public void init(int num) {
        friendNum = num;
        Tools.printLog("friendNum = " + num);
        id = new long[num];
        name = new String[num];
        level = new int[num];
        duty = new String[num];
        online = new byte[num];
    }

    public void init(int index, long friendId, String friendName, int friendLevel, String friendDuty, byte friendOnline) {
        Tools.printLog("index = " + index + ", friendId = " + friendId + ", friendName = " + friendName
                + ", friendLevel = " + friendLevel + ", duty = " + friendDuty + ", onLine = " + friendOnline);
        if (friendDuty.equals("Paladin") || friendDuty.equals("Paladin1")) {
            friendDuty = "刺客";
        } else if (friendDuty.equals("Hercules") || friendDuty.equals("Hercules1")) {
            friendDuty = "武师";
        } else if (friendDuty.equals("Master") || friendDuty.equals("Master1")) {
            friendDuty = "术士";
        }
        id[index] = friendId;
        name[index] = friendName;
        level[index] = friendLevel;
        duty[index] = friendDuty;
        online[index] = friendOnline;
        //排序
        setOrder();
    }

    public void setOrder() {//对好友列表进行排序；在线的靠前，其次是等级高的
        if (GameBean.BY_CMD_FRIEND_TYPE != 4) {
            long tempId = -1;
            String tempDuty = null;
            int tempLevel = -1;
            String tempName = null;
            byte tempOnline = -1;
            for (int i = 0; i < level.length; i++) {
                for (int j = i; j < level.length; j++) {
                    if (level[i] < level[j]) {//按级别由高到低排序
                        tempId = id[i];
                        tempDuty = duty[i];
                        tempLevel = level[i];
                        tempName = name[i];
                        tempOnline = online[i];

                        id[i] = id[j];
                        duty[i] = duty[j];
                        level[i] = level[j];
                        name[i] = name[j];
                        online[i] = online[j];

                        id[j] = tempId;
                        duty[j] = tempDuty;
                        level[j] = tempLevel;
                        name[j] = tempName;
                        online[j] = tempOnline;
                    }

                    if (online[i] != 1 && online[j] == 1) {//先显示在线的
                        tempId = id[i];
                        tempDuty = duty[i];
                        tempLevel = level[i];
                        tempName = name[i];
                        tempOnline = online[i];

                        id[i] = id[j];
                        duty[i] = duty[j];
                        level[i] = level[j];
                        name[i] = name[j];
                        online[i] = online[j];

                        id[j] = tempId;
                        duty[j] = tempDuty;
                        level[j] = tempLevel;
                        name[j] = tempName;
                        online[j] = tempOnline;
                    }
                }
            }
        }
    }

    public void drawFriendList(Graphics g) {
        //绘制背景
        startX = Constant.UI_START_X + 0;
        startY = Constant.UI_START_Y + 0;
        //#if NOKIA_S60V5
         Tools.drawS60V5Frame(g, imgArray[0], imgArray[7], imgArray[8], imgArray[9], imgArray[4], sArray[0]);
         h = 41;
         startY = Constant.UI_START_Y + 41 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#else
//#        h = imgArray[4].getHeight();
//#        Tools.drawFrame(g, imgArray[0], imgArray[3], sArray[22], sArray[23], sArray[0]);
//#        h = 30;
//#        startY = Constant.UI_START_Y + 21 + (h - Constant.FONT_SMALL_HEIGHT >> 1);
        //#endif
        //绘制顶层选项
        w = Constant.DRAW_WIDTH / 3;
        for (int i = 0; i < 3; i++) {
            //#if NOKIA_S60V5
             startX = Constant.UI_START_X + w * i + (w - Constant.FONT_SMALL.stringWidth(sArray[i + 5]) >> 1);
             Tools.drawShadowString(g, (byte) 1, sArray[i + 5], startX, startY,
                     i == bySubSelectIndex - 1 ? selectColor : whiteColor, blackColor);
            //#else
//#            startX = Constant.UI_START_X + w * i + (w - Constant.FONT_SMALL.stringWidth(sArray[i + 19]) >> 1);
//#            Tools.drawShadowString(g, (byte) 1, sArray[i + 19], startX, startY,
//#                    i == bySubSelectIndex - 1 ? selectColor : whiteColor, blackColor);
            //#endif
        }
        //绘制选项两边箭头
        //#if NOKIA_S60V5
         startX = Constant.UI_START_X + w * (bySubSelectIndex - 1)
                 + (w - Constant.FONT_SMALL.stringWidth(sArray[bySubSelectIndex + 4]) >> 1) - 5 - 3;//5为箭头宽度
        //#else
//#        startX = Constant.UI_START_X + w * (bySubSelectIndex - 1)
//#                + (w - Constant.FONT_SMALL.stringWidth(sArray[bySubSelectIndex + 18]) >> 1) - 5 - 3;//5为箭头宽度
        //#endif
        startY = startY + (Constant.FONT_SMALL_HEIGHT - 7 >> 1);//7为箭头高度
        Tools.drawArrow(g, imgArray[2], (byte) 1, startX, startY);//向左的箭头
        //#if NOKIA_S60V5
         startX = startX + 5 + 3 + Constant.FONT_SMALL.stringWidth(sArray[bySubSelectIndex + 4]) + 3;
        //#else
//#        startX = startX + 5 + 3 + Constant.FONT_SMALL.stringWidth(sArray[bySubSelectIndex + 18]) + 3;
        //#endif
        Tools.drawArrow(g, imgArray[2], (byte) 2, startX, startY);//向右的箭头
        //绘制顶层选项蓝光
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + 41 + h;
        //#else
//#        startY = Constant.UI_START_Y + 21 + h;
        //#endif
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        Tools.drawSelectMask(g, (byte) 1, imgArray[3], startX, startY, w);
        //绘制半透明背景
        //#if NOKIA_S60V5
         h = Constant.END_LINE - 41 - h;
        //#else
//#        h = Constant.DRAW_HEIGHT - 21 - 25 - h;
        //#endif
        Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[1], 0, 0, w, imgArray[1].getHeight(), Constant.TRANS_NONE);
        //绘制翻页
        //#if NOKIA_S60V5
         startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 57 + (57 - imgArray[6].getHeight() >> 1);
        //#else
//#        startY = Constant.UI_START_Y + Constant.DRAW_HEIGHT - 25 + (25 - imgArray[6].getHeight() >> 1);
        //#endif
        startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Tools.getPageStrWidth(sTotalPage, sCurrentPage) >> 1);
        Tools.drawPage(g, sTotalPage, sCurrentPage, imgArray[6], imgArray[2], startX, startY);
        //绘制添加好友
        //#if NOKIA_S60V5
         h = h / (num + 1);
        //#else
//#        h = Constant.FONT_SMALL_HEIGHT + 1;
        //#endif
        if (bySubSelectIndex < 3) {
            //#if NOKIA_S60V5
             startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1);
            //#else
//#            startY = Constant.UI_START_Y + 65;
            //#endif
            String str_temp = "";
            switch (GameBean.BY_CMD_FRIEND_TYPE) {
                case 1://好友
                    str_temp = sArray[1] + sArray[5] + sArray[15] + sArray[2];
                    break;
                case 2://黑名单
                    str_temp = sArray[1] + sArray[6] + sArray[15] + sArray[2];
                    break;
            }
            startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - Constant.FONT_SMALL.stringWidth(str_temp) >> 1);
            Tools.drawShadowString(g, (byte) 1, str_temp, startX, startY, selectColor, blackColor);
        }
        //绘制好友列表
        w = Constant.FONT_SMALL.stringWidth(sArray[18]);
        int temp = (sCurrentPage * num < friendNum) ? sCurrentPage * num : friendNum;
        for (int i = (sCurrentPage - 1) * num; i < temp; i++) {
            startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
            //#if NOKIA_S60V5
             startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1)
                     + h + h * (i - (sCurrentPage - 1) * num);
            //#else
//#            startY = Constant.UI_START_Y + 65 + h + h * (i - (sCurrentPage - 1) * num);
            //#endif
            Tools.drawShadowString(g, (byte) 1, sArray[12] + duty[i] + sArray[13], startX,
                    startY, selectColor, blackColor);
            startX = startX + Constant.FONT_SMALL.stringWidth(sArray[12] + duty[i] + sArray[13]);
            Tools.drawShadowString(g, (byte) 1, level[i] + sArray[14] + name[i], startX, startY,
                    online[i] == 1 ? whiteColor : 0x999999, blackColor);
        }
        //绘制选择条
        startX = Constant.UI_START_X + 0;
        w = Constant.DRAW_WIDTH;
        if (bySelectIndex == 1) {
            Tools.drawSelectMask(g, (byte) 2, imgArray[3], startX, iPositionY, w);
        } else {
            //#if NOKIA_S60V5
             h = (Constant.END_LINE - (41 << 1)) / (num + 1);
            //#else
//#            h = Constant.FONT_SMALL_HEIGHT + 1;
            //#endif
            Tools.drawGapSlectMask(g, imgArray[3], null, false, h, startX, iPositionY, w);
        }
        if (byState == 1) {
            startX = Constant.UI_START_X + 0;
            startY = Constant.UI_START_Y + 0;
            w = Constant.DRAW_WIDTH;
            //#if NOKIA_S60V5
             h = Constant.END_LINE;
            //#else
//#            h = Constant.DRAW_HEIGHT;
            //#endif
            //背景遮罩
            Tools.drawTilePic(g, (byte) 2, startX, startY, h, imgArray[1], 0, 0, w, imgArray[1].getHeight(), Constant.TRANS_NONE);
            //弹出菜单
            Tools.drawPopOperation(g, imgArray[5], 0x989898, 0x7c7c7c, menuName, menuWidth, menuH,
                    menuSpaceH, whiteColor, selectColor, menuSelectIndex, 0, 0);
            //绘制选择条
            startX = Constant.UI_START_X + 0;
            w = Constant.DRAW_WIDTH;
            //#if NOKIA_S60V5
             Tools.drawSelectMask(g, (byte) 1, imgArray[3], startX, menuPositionY, w, imgArray[2],
                     imgArray[4], 100, 3, 45, 20, imgArray[4], 1, 2, 47, 21);
            //#else
//#            h = imgArray[4].getHeight();
//#            Tools.drawSelectMask(g, (byte) 1, imgArray[3], startX, menuPositionY, w, imgArray[2], imgArray[4], 0, 0, 24, h,
//#                    imgArray[4], 49, 0, 23, h);
            //#endif
             MainView.drawTouchRect(g, mfreindOperation);
        } else {
            MainView.drawTouchRect(g, mfreindListRect);
        }
        
        ////////////
        //Yujiang
        MainView.drawTouchRect(g, mFriendListTopTouchRect);
    }

    public void updateFriendList() {
        if (GameBean.b_WAIT_NET_MSG_BACK) {
            return;
        }
        if (!bUiKeyPressLock) {
            switch (byState) {
                case 0:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == 1) {
                            if (bySubSelectIndex == 3) {
                                if (selectNum > 2) {
                                    //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                             startY = Constant.UI_START_Y + (41 << 1) + h * (selectNum - 2);
                                    //#else
//#                                    h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                    startY = Constant.UI_START_Y + 65 + h * (selectNum - 2);
                                    //#endif
                                } else {
                                    return;
                                }
                            } else {
                                //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                             startY = Constant.UI_START_Y + (41 << 1) + h * (selectNum - 2);
                                //#else
//#                                h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                startY = Constant.UI_START_Y + 65 + h * (selectNum - 2);
                                //#endif
                            }
                        } else if (bySelectIndex == 2) {
                            //#if NOKIA_S60V5
                             startY = Constant.UI_START_Y + 41;
                            //#else
//#                            startY = Constant.UI_START_Y + 21;
                            //#endif
                        } else if (bySelectIndex == 3) {
                            if (bySubSelectIndex == 3) {
                                //#if NOKIA_S60V5
                                 startY = Constant.UI_START_Y + 41;
                                //#else
//#                                startY = Constant.UI_START_Y + 21;
                                //#endif
                                bySelectIndex--;
                            } else {
                                //#if NOKIA_S60V5
                                 h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                                 startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 3);
                                //#else
//#                                h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 3);
                                //#endif
                            }
                        } else {
                            //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                             startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 3);
                            //#else
//#                            h = Constant.FONT_SMALL_HEIGHT + 1;
//#                            startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 3);
                            //#endif
                        }
                        bySelectIndex = (byte) (bySelectIndex == 1 ? selectNum : (bySelectIndex - 1));
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == 1) {
                            if (bySubSelectIndex == 3) {
                                if (friendNum > 0) {
                                    //#if NOKIA_S60V5
                                     h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                                     startY = Constant.UI_START_Y + (41 << 1) + h;
                                    //#else
//#                                    h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                    startY = Constant.UI_START_Y + 65 + h;
                                    //#endif
                                    bySelectIndex++;
                                } else {
                                    return;
                                }
                            } else {
                                //#if NOKIA_S60V5
                                 startY = Constant.UI_START_Y + (41 << 1);
                                //#else
//#                                startY = Constant.UI_START_Y + 65;
                                //#endif
                            }
                        } else if (bySelectIndex == selectNum) {
                            //#if NOKIA_S60V5
                             startY = Constant.UI_START_Y + 41;
                            //#else
//#                            startY = Constant.UI_START_Y + 21;
                            //#endif
                        } else {
                            //#if NOKIA_S60V5
                             h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                             startY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 1);
                            //#else
//#                            h = Constant.FONT_SMALL_HEIGHT + 1;
//#                            startY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 1);
                            //#endif
                        }
                        bySelectIndex = (byte) (bySelectIndex == selectNum ? 1 : (bySelectIndex + 1));
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_LEFT, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == 1) {
                            switch (bySubSelectIndex) {
                                case 1://好友 → 最近联系
                                    GameBean.BY_CMD_FRIEND_TYPE = 4;
                                    break;
                                case 2://黑名单  →  好友
                                    GameBean.BY_CMD_FRIEND_TYPE = 1;
                                    break;
                                case 3://最近联系 → 黑名单
                                    GameBean.BY_CMD_FRIEND_TYPE = 2;
                                    break;
                            }
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_FRIEND_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                            GameBean.b_WAIT_NET_MSG_BACK = true;
                            bySubSelectIndex = (byte) (bySubSelectIndex == 1 ? 3 : (bySubSelectIndex - 1));
                        } else {
                            if (sCurrentPage > 1) {
                                sCurrentPage--;
                                selectNum = (byte) ((sCurrentPage * num < friendNum) ? num + 2 : (byte) (friendNum - (sCurrentPage - 1) * num + 2));
                                bySelectIndex = 3;
                                //#if NOKIA_S60V5
                                 h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                                 iPositionY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 2);
                                //#else
//#                                h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                iPositionY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 2);
                                //#endif
                            }
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_RIGHT, false)) {
                        bUiKeyPressLock = true;
                        if (bySelectIndex == 1) {
                            switch (bySubSelectIndex) {
                                case 1://好友 → 黑名单
                                    GameBean.BY_CMD_FRIEND_TYPE = 2;
                                    break;
                                case 2://黑名单 → 最近联系
                                    GameBean.BY_CMD_FRIEND_TYPE = 4;
                                    break;
                                case 3://最近联系 → 好友
                                    GameBean.BY_CMD_FRIEND_TYPE = 1;
                                    break;
                            }
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_FRIEND_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                            GameBean.b_WAIT_NET_MSG_BACK = true;
                            bySubSelectIndex = (byte) (bySubSelectIndex == 3 ? 1 : (bySubSelectIndex + 1));
                        } else {
                            if (sCurrentPage < sTotalPage) {
                                sCurrentPage++;
                                selectNum = (byte) ((sCurrentPage * num < friendNum) ? num + 2 : (byte) (friendNum - (sCurrentPage - 1) * num + 2));
                                bySelectIndex = 3;
                                //#if NOKIA_S60V5
                                 h = (Constant.END_LINE - (41 << 1)) / (num + 1);
                                 iPositionY = Constant.UI_START_Y + (41 << 1) + h * (bySelectIndex - 2);
                                //#else
//#                                h = Constant.FONT_SMALL_HEIGHT + 1;
//#                                iPositionY = Constant.UI_START_Y + 65 + h * (bySelectIndex - 2);
                                //#endif
                            }
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_1, false)) {
                        if (bySubSelectIndex != 1) {
                            GameBean.BY_CMD_FRIEND_TYPE = 1;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_FRIEND_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                            GameBean.b_WAIT_NET_MSG_BACK = true;
                            bySubSelectIndex = 1;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_2, false)) {
                        if (bySubSelectIndex != 2) {
                            GameBean.BY_CMD_FRIEND_TYPE = 2;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_FRIEND_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                            GameBean.b_WAIT_NET_MSG_BACK = true;
                            bySubSelectIndex = 2;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_3, false)) {
                        if (bySubSelectIndex != 3) {
                            GameBean.BY_CMD_FRIEND_TYPE = 3;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_FRIEND_LIST, Constant.SOCKET_MSG_TYPE_LOGIC);
                            GameBean.b_WAIT_NET_MSG_BACK = true;
                            bySubSelectIndex = 3;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
                        if (GameBean.BY_PRE_GAME_UI_STATE == Constant.GAME_UI_CHAT) {
//                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                            MainLogic.getInstance().pushState(Constant.GAME_UI_CHAT, true);
                            MainLogic.getInstance().uiEquipment.chatindex = 0;
                            MainLogic.getInstance().uiEquipment.chatSelectindex = 3;
                            MainLogic.getInstance().inputInterFace.setInputInterFace((byte) 0, "私聊发送聊天");
//                            MainLogic.getInstance().inputInterFace.commonInput.setString(this.sStrArray[0]);
                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
//                            MainLogic.getInstance().inputInterFace.commonInput.setString(this.sStrArray[0]);
                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                        } else if (GameBean.BY_PRE_GAME_UI_STATE == Constant.GAME_UI_SEND_EMAIL) {
                            MainLogic.getInstance().pushState(Constant.GAME_UI_SEND_EMAIL, true);
                            Constant.CMD_MAIL_TYPE = 0;
                        } else if (GameBean.BY_PRE_GAME_UI_STATE == Constant.GAME_UI_SENDINPUT_EMAIL) {
                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
//                            MainLogic.getInstance().pushState(Constant.GAME_UI_SEND_EMAIL, true);
                        } else {
                            bUiKeyPressLock = true;
                            //返回上一级菜单
                            Tools.openRoamMenu(false, (byte) 1, (byte) 8, 3);
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false)) {
                        bUiKeyPressLock = true;
                        if ((GameBean.BY_PRE_GAME_UI_STATE == Constant.GAME_UI_SEND_EMAIL
                                || GameBean.BY_PRE_GAME_UI_STATE == Constant.GAME_UI_SENDINPUT_EMAIL)
                                && friendNum > 0) {//从邮件界面进入
                            GameBean.BY_CMD_FRIEND_NAME = name[(sCurrentPage - 1) * num + bySelectIndex - 3];
                            MainLogic.getInstance().pushState(Constant.GAME_UI_SEND_EMAIL, true);
                            Constant.CMD_MAIL_TYPE = 0;
//                            MainLogic.getInstance().uiEquipment.initSendMail();
                            MainLogic.uiEquipment.sendEmail_name = GameBean.BY_CMD_FRIEND_NAME;
                            GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_MAIL_CHECKUSER, Constant.SOCKET_MSG_TYPE_LOGIC);
                        } else if (GameBean.BY_PRE_GAME_UI_STATE == Constant.GAME_UI_CHAT
                                && friendNum > 0 && this.bySelectIndex >= 3) {
                            MainLogic.getInstance().uiEquipment.chatOtherplayerName = name[(sCurrentPage - 1) * num + bySelectIndex - 3];
                            MainLogic.getInstance().uiEquipment.chatOtherplayerId = id[(sCurrentPage - 1) * num + bySelectIndex - 3];//发送对象Id
//                            System.out.println("MainLogic.getInstance().uiEquipment.chatOtherplayerName ::: " + MainLogic.getInstance().uiEquipment.chatOtherplayerName);
                            MainLogic.getInstance().pushState(Constant.GAME_UI_CHAT, true);
                            MainLogic.getInstance().uiEquipment.chatindex = 0;
                            MainLogic.getInstance().uiEquipment.chatSelectindex = 3;
                            MainLogic.getInstance().inputInterFace.setInputInterFace((byte) 0, "私聊发送聊天");
//                            MainLogic.getInstance().inputInterFace.commonInput.setString(this.sStrArray[0]);
                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
//                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                            MainLogic.getInstance().inputInterFace.choiceGroupPrivate.set(0, MainLogic.getInstance().uiEquipment.chatOtherplayerName, null);
                        } else {
                            if (bySelectIndex == 2) {
                                switch (bySubSelectIndex) {
                                    case 1:
                                        MainLogic.inputInterFace.setInputInterFace((byte) 1, "添加好友");
                                        break;
                                    case 2:
                                        MainLogic.inputInterFace.setInputInterFace((byte) 2, "添加黑名单");
                                        break;
                                }
                                MainGame.changeCanvas(MainLogic.inputInterFace);
                            } else if (bySelectIndex > 1) {
                                //#if NOKIA_S60V5
                                 menuH = (Constant.END_LINE - (41 << 1)) / (num + 1);
                                 menuSpaceH = 10;
                                //#elif NOKIA_E72
//#                                 menuH = Constant.FONT_SMALL_HEIGHT + 2;
//#                                 menuSpaceH = 4;
                                //#else
//#                                menuH = Constant.FONT_SMALL_HEIGHT + 2;
//#                                menuSpaceH = 10;
                                //#endif
                                menuWidth = Constant.DRAW_WIDTH >> 1;
                                switch (bySubSelectIndex) {
                                    case 1://好友
                                        menuName = new String[]{"查看信息", "发送信息", "组队申请", "帮会邀请", "发送邮件", "发起交易", "转到黑名单", "移除好友", "查看摊位"};
                                        menuSelectIndex = 4;
                                        menuHeight = menuName.length * (menuH + menuSpaceH) - menuSpaceH;
                                        break;
                                    case 2://黑名单
                                        menuName = new String[]{"查看信息", "转到好友", "移除黑名单"};
                                        menuSelectIndex = 2;
                                        menuHeight = menuName.length * (menuH + menuSpaceH) - menuSpaceH;
                                        break;
                                    case 3://最近联系
                                        menuName = new String[]{"查看信息", "发送信息", "组队申请", "帮会邀请", "发送邮件", "发起交易", "转到黑名单", "转到好友"};
                                        menuSelectIndex = 4;
                                        menuHeight = menuName.length * (menuH + menuSpaceH) - menuSpaceH;
                                        break;
                                }
                                //#if NOKIA_S60V5
                                 startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                         + menuSelectIndex * (menuH + menuSpaceH);
                                //#else
//#                                startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                        + menuSelectIndex * (menuH + menuSpaceH);
                                //#endif
                                iArray = new int[]{1, 1, startY, 2, 50, 5};
                                byState = 1;
                            }
                        }
                    }
                    break;
                case 1:
                    if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_UP, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == 1 ? menuName.length : (menuSelectIndex - 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{2, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_DOWN, false)) {
                        bUiKeyPressLock = true;
                        menuSelectIndex = (byte) (menuSelectIndex == menuName.length ? 1 : (menuSelectIndex + 1));
                        //#if NOKIA_S60V5
                         startY = Constant.UI_START_Y + (Constant.END_LINE - menuHeight >> 1)
                                 + menuSelectIndex * (menuH + menuSpaceH);
                        //#else
//#                        startY = Constant.UI_START_Y + (Constant.DRAW_HEIGHT - menuHeight >> 1)
//#                                + menuSelectIndex * (menuH + menuSpaceH);
                        //#endif
                        iArray = new int[]{1, 1, startY, 2, 50, 5};
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_POSITIVE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_FIRE, false) || MainCanvas.keyPressedLogic(Constant.GAME_KEY_5, false)) {
                        tempIndex = (sCurrentPage - 1) * num + bySelectIndex - 3;
                        switch (bySubSelectIndex) {
                            case 1://好友
                                switch (menuSelectIndex) {
                                    case 1://查看信息
                                        if (online[tempIndex] == 1) {
                                            GameBean.L_PLAYER_ID = id[tempIndex];
                                            GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_OTHER_PLAYER_DETAIL, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方不在线，不能进行查看操作!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                    case 2://发送信息
                                        if (online[tempIndex] == 1) {
                                            GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                            GameBean.BY_CMD_FRIEND_TYPE = 1;
                                            GameBean.L_PLAYER_ID = id[tempIndex];
                                            UiEquipment.chatOtherplayerId = id[tempIndex];//发送对象Id
                                            MainLogic.getInstance().uiEquipment.chatOtherplayerName = name[tempIndex];
                                            MainLogic.getInstance().uiEquipment.chatshoutType = 3;
                                            MainLogic.getInstance().pushState(Constant.GAME_UI_CHAT, true);
                                            MainLogic.getInstance().inputInterFace.setInputInterFace(Constant.GAME_UI_CHAT, "私聊发送聊天");
                                            MainLogic.getInstance().inputInterFace.commonInput.setString(null);
                                            MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方不在线，不能进行私聊操作!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                    case 3://组队申请
                                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "战场中不允许组队!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10301")
                                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10401")
                                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10501")) {//副本
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "副本中不允许组队!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else {
                                            if (online[tempIndex] == 1) {
                                                if (MainLogic.getInstance().uiInterFace.team.getTeamMemberNum() <= 0) {
                                                    GameBean.L_PLAYER_ID = id[tempIndex];
                                                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请求已经发出!", (byte) 1, (byte) -1);
                                                    byState = 0;
                                                } else if (MainLogic.getInstance().uiInterFace.team.getTeamMemberNum() < Constant.MAX_TEAM_MEMBER_NUM) {
                                                    if (MainLogic.getInstance().uiInterFace.team.getMemberPos(GameBean.L_PLAYER_ID) != -1) {
                                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "该玩家已在您的队伍中!", (byte) 1, (byte) -1);
                                                    } else if (!MainLogic.getInstance().uiInterFace.team.isMeLeader()) {
                                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "只有队长才能邀请玩家入队!", (byte) 1, (byte) -1);
                                                    } else {
                                                        GameBean.L_PLAYER_ID = id[tempIndex];
                                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请求已经发出!", (byte) 1, (byte) -1);
                                                        byState = 0;
                                                    }
                                                } else {
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "队伍人数已满!", (byte) 1, (byte) -1);
                                                }
                                            } else {
                                                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已下线！", (byte) 1, (byte) -1);
                                            }
                                        }
                                        break;
                                    case 4://帮会邀请
                                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已有帮派!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else {
                                            if (online[tempIndex] == 1) {
                                                if (MainLogic.getInstance().gamePlayer.sTongName == null) {
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "您没有邀请其他玩家加入帮派的权力!", (byte) 1, (byte) -1);
                                                } else if (level[tempIndex] < 20) {
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方级别尚低，不能加入帮派!", (byte) 1, (byte) -1);
                                                } else {
                                                    GameBean.L_PLAYER_ID = id[tempIndex];
                                                    GameBean.BY_CMD_INVITE_TONG_TYPE = 1;
                                                    MainLogic.getInstance().send(Constant.MSG_NET_INVITE_TONG, Constant.SOCKET_MSG_TYPE_LOGIC);
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请求已经发出!", (byte) 1, (byte) -1);
                                                    byState = 0;
                                                }
                                            } else {
                                                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已下线!", (byte) 1, (byte) -1);
                                            }
                                        }
                                        break;
                                    case 5://发送邮件
                                        GameBean.BY_CMD_FRIEND_NAME = name[tempIndex];
                                        MainLogic.getInstance().pushState(Constant.GAME_UI_SEND_EMAIL, true);
                                        Constant.CMD_MAIL_TYPE = 0;
                                        MainLogic.getInstance().uiEquipment.initSendMail();
                                        MainLogic.uiEquipment.sendEmail_name = GameBean.BY_CMD_FRIEND_NAME;
                                        GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_MAIL_CHECKUSER, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        break;
                                    case 6://发起交易
                                        if (online[tempIndex] == 1) {
                                            GameBean.L_PLAYER_ID = id[tempIndex];
                                            GameBean.BY_TYPE = 1;//(1,交易,2:切磋)
                                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TRADE_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                            MainLogic.uiInterFace.sysMessage.showMessage("提示", "交易请求已发出!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已下线!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                    case 7://转到黑名单
                                        GameBean.BY_CMD_FRIEND_NAME = name[tempIndex];
                                        GameBean.BY_CMD_FRIEND_TYPE = 2;
                                        GameBean.BY_CMD_FRIEND_MODE = 1;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_ADD_FRIEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        GameBean.b_WAIT_NET_MSG_BACK = true;
                                        break;
                                    case 8://移除好友
                                        GameBean.BY_CMD_FRIEND_ID = id[tempIndex];
                                        GameBean.BY_CMD_FRIEND_TYPE = 1;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_DEL_FREIND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        GameBean.b_WAIT_NET_MSG_BACK = true;
                                        break;
                                    case 9://查看摊位
                                        if (online[tempIndex] == 1) {
                                            MainLogic.getInstance().getInstance().uiInterFace.store.openStall(id[tempIndex]);
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方不在线，不能进行查看操作!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                }
                                break;
                            case 2://黑名单
                                switch (menuSelectIndex) {
                                    case 1://查看信息
                                        if (online[tempIndex] == 1) {
                                            GameBean.L_PLAYER_ID = id[tempIndex];
                                            GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_OTHER_PLAYER_DETAIL, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方不在线，不能进行查看操作!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                    case 2://转到好友
                                        GameBean.BY_CMD_FRIEND_NAME = name[tempIndex];
                                        GameBean.BY_CMD_FRIEND_TYPE = 1;
                                        GameBean.BY_CMD_FRIEND_MODE = 1;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_ADD_FRIEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        GameBean.b_WAIT_NET_MSG_BACK = true;
                                        break;
                                    case 3://移除黑名单
                                        GameBean.BY_CMD_FRIEND_ID = id[tempIndex];
                                        GameBean.BY_CMD_FRIEND_TYPE = 2;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_DEL_FREIND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        GameBean.b_WAIT_NET_MSG_BACK = true;
                                        break;
                                }
                                break;
                            case 3://最近联系
                                switch (menuSelectIndex) {
                                    case 1://查看信息
                                        if (online[tempIndex] == 1) {
                                            GameBean.L_PLAYER_ID = id[tempIndex];
                                            GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_OTHER_PLAYER_DETAIL, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方不在线，不能进行查看操作!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                    case 2://发送信息
                                        GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                        GameBean.BY_CMD_FRIEND_TYPE = 4;
                                        GameBean.L_PLAYER_ID = id[tempIndex];
                                        UiEquipment.chatOtherplayerId = id[tempIndex];//发送对象Id
                                        MainLogic.getInstance().uiEquipment.chatOtherplayerName = name[tempIndex];
                                        if (MainLogic.getInstance().uiEquipment.chatOtherplayerName.equals(MainLogic.getInstance().gamePlayer.sPlayerName)) {
                                            MainLogic.getInstance().uiEquipment.chatOtherplayerName = "";
                                        }
                                        MainLogic.getInstance().uiEquipment.chatshoutType = 3;
                                        MainLogic.getInstance().pushState(Constant.GAME_UI_CHAT, true);
                                        MainLogic.getInstance().inputInterFace.setInputInterFace(Constant.GAME_UI_CHAT, "私聊发送聊天");
                                        MainLogic.getInstance().inputInterFace.commonInput.setString(null);
                                        MainGame.changeCanvas(MainLogic.getInstance().inputInterFace);
                                        break;
                                    case 3://组队申请
                                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "战场中不允许组队!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10301")
                                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10401")
                                                || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10501")) {//副本
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "副本中不允许组队!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else {
                                            if (online[tempIndex] == 1) {
                                                if (MainLogic.getInstance().uiInterFace.team.getTeamMemberNum() <= 0) {
                                                    GameBean.L_PLAYER_ID = id[tempIndex];
                                                    MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请求已经发出!", (byte) 1, (byte) -1);
                                                    byState = 0;
                                                } else if (MainLogic.getInstance().uiInterFace.team.getTeamMemberNum() < Constant.MAX_TEAM_MEMBER_NUM) {
                                                    if (MainLogic.getInstance().uiInterFace.team.getMemberPos(GameBean.L_PLAYER_ID) != -1) {
                                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "该玩家已在您的队伍中!", (byte) 1, (byte) -1);
                                                    } else if (!MainLogic.getInstance().uiInterFace.team.isMeLeader()) {
                                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "只有队长才能邀请玩家入队!", (byte) 1, (byte) -1);
                                                    } else {
                                                        GameBean.L_PLAYER_ID = id[tempIndex];
                                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_TEAM_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                                        MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请求已经发出!", (byte) 1, (byte) -1);
                                                        byState = 0;
                                                    }
                                                } else {
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "队伍人数已满!", (byte) 1, (byte) -1);
                                                }
                                            } else {
                                                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已下线!", (byte) 1, (byte) -1);
                                            }
                                        }
                                        break;
                                    case 4://帮会邀请
                                        if (MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10101") || MainLogic.getInstance().uiInterFace.sRoamMapKeys.equals("10201")) {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已有帮派!", (byte) 1, (byte) -1);
                                            byState = 0;
                                        } else {
                                            if (online[tempIndex] == 1) {
                                                if (MainLogic.getInstance().gamePlayer.sTongName == null) {
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "您没有邀请其他玩家加入帮派的权力!", (byte) 1, (byte) -1);
                                                } else if (level[tempIndex] < 20) {
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方级别尚低，不能加入帮派!", (byte) 1, (byte) -1);
                                                } else {
                                                    GameBean.L_PLAYER_ID = id[tempIndex];
                                                    GameBean.BY_CMD_INVITE_TONG_TYPE = 1;
                                                    MainLogic.getInstance().send(Constant.MSG_NET_INVITE_TONG, Constant.SOCKET_MSG_TYPE_LOGIC);
                                                    MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "请求已经发出!", (byte) 1, (byte) -1);
                                                    byState = 0;
                                                }
                                            } else {
                                                MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已下线!", (byte) 1, (byte) -1);
                                            }
                                        }
                                        break;
                                    case 5://发送邮件
                                        GameBean.BY_CMD_FRIEND_NAME = name[tempIndex];
                                        MainLogic.getInstance().pushState(Constant.GAME_UI_SEND_EMAIL, true);
                                        Constant.CMD_MAIL_TYPE = 0;
                                        MainLogic.getInstance().uiEquipment.initSendMail();
                                        MainLogic.uiEquipment.sendEmail_name = GameBean.BY_CMD_FRIEND_NAME;
                                        GameBean.BY_PRE_GAME_UI_STATE = Constant.GAME_UI_FRIEND_LIST;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_MAIL_CHECKUSER, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        break;
                                    case 6://发起交易
                                        if (online[tempIndex] == 1) {
                                            GameBean.L_PLAYER_ID = id[tempIndex];
                                            GameBean.BY_TYPE = 1;//(1,交易,2:切磋)
                                            MainLogic.getInstance().send(Constant.MSG_NET_CMD_TRADE_JOIN, Constant.SOCKET_MSG_TYPE_LOGIC);
                                            MainLogic.uiInterFace.sysMessage.showMessage("提示", "交易请求已发出!", (byte) 1, (byte) -1);
                                        } else {
                                            MainLogic.getInstance().uiInterFace.sysMessage.showMessage("提示", "对方已下线!", (byte) 1, (byte) -1);
                                        }
                                        break;
                                    case 7://转到黑名单
                                        GameBean.BY_CMD_FRIEND_NAME = name[tempIndex];
                                        GameBean.BY_CMD_FRIEND_TYPE = 2;
                                        GameBean.BY_CMD_FRIEND_MODE = 1;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_ADD_FRIEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        GameBean.b_WAIT_NET_MSG_BACK = true;
                                        break;
                                    case 8://添加好友
                                        GameBean.BY_CMD_FRIEND_NAME = name[tempIndex];
                                        GameBean.BY_CMD_FRIEND_TYPE = 1;
                                        GameBean.BY_CMD_FRIEND_MODE = 1;
                                        MainLogic.getInstance().send(Constant.MSG_NET_CMD_ADD_FRIEND, Constant.SOCKET_MSG_TYPE_LOGIC);
                                        GameBean.b_WAIT_NET_MSG_BACK = true;
                                        break;
                                }
                                break;
                        }
                    } else if (MainCanvas.keyPressedLogic(Constant.GAME_KEY_NEGATIVE, false)) {
                        bUiKeyPressLock = true;
                        byState = 0;
                    }
                    break;
            }
        } else {
            switch (byState) {
                case 0:
                    iPositionY = Tools.updateLinePos(iArray, iPositionY);
                    break;
                case 1:
                    menuPositionY = Tools.updateLinePos(iArray, menuPositionY);
                    break;
                case 2:
                    break;
            }
            if (iArray == null || iArray[1] == 0) {
                bUiKeyPressLock = false;
            }
        }
    }

    public void clearFriendList() {
        imgArray = null;
        sArray = null;
        iArray = null;
        menuName = null;
        duty = null;
        level = null;
        id = null;
        name = null;
        online = null;
    }
    
    ////////////////////
    public static int[][] mFriendListTopTouchRect = new int[][]{
    	{0,40,120,40},{120,40,120,40},{240,40,120,40}
    };
    private static int[][] mbottomToucheRect = new int[][]{
    	{123,588,57,46},
    	{123+57,588,57,46},
    };
    private static int[][] mfreindListRect,mfreindOperation;
    public void checkTouchFriendList(int x, int y) {
		switch (byState) {
		case 0:
			int touched = MainCanvas.checkTouch(x, y, mFriendListTopTouchRect);
			if (touched >= 0) {
				bySelectIndex = 1;
				bySubSelectIndex = (byte) (touched + 1);
				switch (bySubSelectIndex) {
				case 1:// 好友
					GameBean.BY_CMD_FRIEND_TYPE = 1;
					break;
				case 2:// 黑名单
					GameBean.BY_CMD_FRIEND_TYPE = 2;
					break;
				case 3:// 最近联系
					GameBean.BY_CMD_FRIEND_TYPE = 4;
					break;
				}
				MainLogic.getInstance().send(Constant.MSG_NET_CMD_FRIEND_LIST,
						Constant.SOCKET_MSG_TYPE_LOGIC);
				GameBean.b_WAIT_NET_MSG_BACK = true;
				// bySubSelectIndex = (byte) (bySubSelectIndex == 3 ? 1 :
				// (bySubSelectIndex + 1));
			} else {
				touched = MainCanvas.checkTouch(x, y, mbottomToucheRect);
				if (touched >= 0) {
					if (touched == 0) {
						MainCanvas.pressDir(2);
					} else {
						MainCanvas.pressDir(3);
					}
				} else {
					//添加好友或黑名单。
					 if (bySubSelectIndex < 3) {
						 int[][] modifyRect = new int[][]{
								 {0,82,360,116-82},
						 };	
						 touched = MainCanvas.checkTouch(x, y, modifyRect);
						 if (touched >=0 ) {
							if (bySelectIndex == 2) {
								MainCanvas.pressFire();		
							} else {
								if (bySelectIndex > 2) {//向上
				        			bySelectIndex = 3;
				        			MainCanvas.pressDir(0);
//				        			iArray = new int[]{2, 1, startY, 2, 50, 5};
				        		} else {
				        			bySelectIndex = 1;
				        			MainCanvas.pressDir(1);
//				        			iArray = new int[]{1, 1, startY, 2, 50, 5};
				        		}
							}
							 break;
						 }
					 }
					
					// list表
			        int startY = 116;
			        int off = 3;
					int temp = (sCurrentPage * num < friendNum) ? sCurrentPage * num : friendNum;
					int drawstart = (sCurrentPage - 1) * num;
//					if (mfreindListRect == null) {
						mfreindListRect = new int[temp-drawstart][];
//					}
			        for (int i = drawstart; i < temp; i++) {
			            startX = Constant.UI_START_X + (Constant.DRAW_WIDTH - w >> 1);
			            //#if NOKIA_S60V5
			             startY = Constant.UI_START_Y + (41 << 1) + (h - Constant.FONT_SMALL_HEIGHT >> 1)
			                     + h + h * (i - drawstart);
			             mfreindListRect[i-drawstart] = new int[]{
			            		 0,startY,360,h
			             };
			            //#else
			//#            startY = Constant.UI_START_Y + 65 + h + h * (i - (sCurrentPage - 1) * num);
			            //#endif
//			            Tools.drawShadowString(g, (byte) 1, sArray[12] + duty[i] + sArray[13], startX,
//			                    startY, selectColor, blackColor);
//			            startX = startX + Constant.FONT_SMALL.stringWidth(sArray[12] + duty[i] + sArray[13]);
//			            Tools.drawShadowString(g, (byte) 1, level[i] + sArray[14] + name[i], startX, startY,
//			                    online[i] == 1 ? whiteColor : 0x999999, blackColor);
			        }
			        touched = MainCanvas.checkTouch(x, y, mfreindListRect);
			        if (touched >= 0) {
			        	if (bySelectIndex == touched+off) {
			        		MainCanvas.pressFire();
			        	} else {
			        		if (bySelectIndex > (byte) (touched + off)) {//向上
			        			bySelectIndex = (byte) (touched + off+1);
			        			MainCanvas.pressDir(0);
//			        			iArray = new int[]{2, 1, startY, 2, 50, 5};
			        		} else {
			        			bySelectIndex = (byte) (touched + off-1);
			        			MainCanvas.pressDir(1);
//			        			iArray = new int[]{1, 1, startY, 2, 50, 5};
			        		}
//			        		bySelectIndex = (byte) (touched + off);
			        	}
			        }
				}

			}
			break;
		case 1:
            startX = Constant.UI_START_X + 0;
            startY = Constant.UI_START_Y + 0;
            w = Constant.DRAW_WIDTH;
            //#if NOKIA_S60V5
             h = Constant.END_LINE;
			mfreindOperation = Tools.getPopOperationRect(imgArray[5], 0x989898, 0x7c7c7c, menuName, menuWidth, menuH,
	                    menuSpaceH, whiteColor, selectColor, menuSelectIndex, 0, 0);
			touched = MainCanvas.checkTouch(x, y, mfreindOperation);
			if (touched >= 0) {
				if (menuSelectIndex == touched+1) {
					MainCanvas.pressFire();
				} else {
					menuSelectIndex = (byte) ((byte) touched+1);
				}
			} else {
				MainCanvas.pressBack();
			}
			break;
		}
		MainCanvas.checkSoftKey();
	}
}
